# coding=utf-8
import cv2
#Sobel算子
img = cv2.imread(r'E:\picture\Lena.jpg')
img = cv2.GaussianBlur(img, (3, 3), 0)#Gauss filter
img1 = img.copy()
x = cv2.Sobel(img1, cv2.CV_16S, 1, 0)
y = cv2.Sobel(img1, cv2.CV_16S, 0, 1)

absX = cv2.convertScaleAbs(x)  # 转回uint8
absY = cv2.convertScaleAbs(y)

dst = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)

#Canny算子
img2 = img.copy()
canny = cv2.Canny(img2, 50, 150)

# 展示不同的图片
titles = ['srcImg','Sobel', 'Canny']
imgs = [img, dst, canny]

for i in range(5):
    cv2.imshow(titles[i], imgs[i])
    cv2.waitKey(1000000)
cv2.destroyAllWindows()